import 'package:flutter/material.dart';

import '../res/color_res.dart';
import 'image_net_widgets.dart';
import 'image_widgets.dart';

class TopImageTextButton extends StatelessWidget {
  final String imagePath;
  final double imageWidth;
  final double imageHeight;
  final String text;
  final int textColor;
  final double textSize;
  final FontWeight fontWeight;
  final int? maxLines;
  final int backgroundColor;
  final double spacing;
  final BoxFit fit;
  final VoidCallback onTap;

  const TopImageTextButton({
    super.key,
    required this.imagePath,
    required this.imageWidth,
    required this.imageHeight,
    required this.text,
    this.textColor = colorGray3,
    this.textSize = 14,
    this.fontWeight = FontWeight.normal,
    this.maxLines,
    this.backgroundColor = colorTransparent,
    this.spacing = 4,
    this.fit = BoxFit.fill,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Center(
        child: Container(
          decoration: BoxDecoration(
            color: Color(backgroundColor),
          ),
          child: IntrinsicHeight(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Image.asset(
                  imagePath,
                  width: imageWidth,
                  height: imageHeight,
                  fit: fit,
                ),
                SizedBox(height: spacing),
                Text(
                  text,
                  style: TextStyle(
                    color: Color(textColor),
                    fontSize: textSize,
                    fontWeight: fontWeight,
                  ),
                  textAlign: TextAlign.center,
                  maxLines: maxLines,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class TopNetImageTextButton extends StatelessWidget {
  final String url;
  final double imageWidth;
  final double imageHeight;
  final String text;
  final int textColor;
  final double textSize;
  final FontWeight fontWeight;
  final int? maxLines;
  final int backgroundColor;
  final double spacing;
  final BoxFit fit;
  final VoidCallback? onTap;

  const TopNetImageTextButton({
    super.key,
    required this.url,
    required this.imageWidth,
    required this.imageHeight,
    required this.text,
    this.textColor = colorGray3,
    this.textSize = 14,
    this.fontWeight = FontWeight.normal,
    this.maxLines,
    this.backgroundColor = colorTransparent,
    this.spacing = 4,
    this.fit = BoxFit.fill,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        decoration: BoxDecoration(
          color: Color(backgroundColor),
        ),
        child: IntrinsicHeight(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SmartNetImage(
                imageUrl: url,
                width: imageWidth,
                height: imageHeight,
                fit: fit,
                clipType: 2,
              ),
              SizedBox(height: spacing),
              Text(
                text,
                style: TextStyle(
                  color: Color(textColor),
                  fontSize: textSize,
                  fontWeight: fontWeight,
                ),
                textAlign: TextAlign.center,
                maxLines: maxLines,
              ),
            ],
          ),
        ),
      ),
    );
  }
}